#include "tm_maya_joints.h"

#include "rob_bateman\Bone.h"

/*

void GetBonesForObject(const MObject& target)
{
	if (target.hasFn(MFn::kTransform))
	{
		//get transform fn for this object
		MFnTransform tar_xform(target);

		//is this bone already in the skeleton?
	}
}

void OutputAnimation(std::ostream &ofs)
{
	ofs << "ANIMCYCLE " 
		<< MFileIO::currentFile().asChar() 
		<< "\n";
	
	// get start and end times
	int StartTime = static_cast<int>(MAnimControl::minTime().as(MTime::kPALFrame));
	int EndTime   = static_cast<int>(MAnimControl::maxTime().as(MTime::kPALFrame));
	float fStartTime = static_cast<float>(MAnimControl::minTime().as(MTime::kSeconds));
	float fEndTime   = static_cast<float>(MAnimControl::maxTime().as(MTime::kSeconds));

	ofs << "\tnumbones " << static_cast<unsigned int>(g_Bones.size()) << std::endl;
	ofs << "\tstart " << (float)fStartTime << std::endl;
	ofs << "\tend "   << (float)fEndTime   << std::endl;
	ofs << "\tnum_frames " << (EndTime-StartTime+1) << std::endl;

	/// a map of all useful transforms
	BoneIT it = g_Bones.begin();
	for( ; it != g_Bones.end(); ++it )
	{
		// attach function set
		MFnTransform fnX(it->second.path);

		// output bone chunk
		ofs << "\tBONEANIM " << it->second.id << std::endl;
		std::cout << "outputting bone anim " << it->first << std::endl;

		for(int i=StartTime;i<=EndTime;++i)
		{
			// set the current time
			MAnimControl::setCurrentTime(MTime(i,MTime::kPALFrame));

			// get rotation
			MQuaternion quat;
			fnX.getRotation(quat);

			// get translation
			MVector trans = fnX.translation(MSpace::kTransform );

			// get scale
			double scale[3];
			fnX.getScale(scale);

			// output keyframe
			ofs << "\t\t" << (float)quat.x   << " "  << (float)quat.y   << " " << (float)quat.z   << " " << (float)quat.w 
				<< "\t" << (float)trans.x  << " "  << (float)trans.y  << " " << (float)trans.z 
				<< "\t" << (float)scale[0] << " "  << (float)scale[1] << " " << (float)scale[2] << std::endl;
		}
	}
}
*/